import Vue from 'vue';
import keys from "./keys.js";
import util from "../util/util.js";
//使用样例：{{item | decode('doccate')}} doccate对应constants.js里的变量名
Vue.filter('decode', function(val, codetype) {
    var res = keys[codetype][val];
    if (typeof(res) == 'undefined') {
        res = '';
    }
    return res;
});
// 调用样例：{{mydate | formatDate("yyyy-MM-dd hh:mm:ss")}}
Vue.filter('formatDate', function(val, fmt) {
    if(val=='' || val ==null){
        return '';
    }
    if (Object.prototype.toString.call(val) === "[object String]") {
        let date = new Date(val.replace(/-/g, '/'));
        return util.formatDate(date, fmt);
    } else {
        if(typeof val=="number"){
            val=new Date(val);
        }
        return util.formatDate(val, fmt);
    }
});
